﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/People.Master" Inherits="System.Web.Mvc.ViewPage<MedicalManagementSystem.Models.Patient>" %>
<%@ Import Namespace="MedicalManagementSystem.Helpers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Добавление пациента
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainRightColumn" runat="server">
    <%= Html.ExportJS("jquery.maskedinput-1.3.min.js") %>
    <h2>Добавление пациента</h2>
    
    <% using (Html.BeginForm()) {%>
    <%= Html.ValidationSummary(false,"Пожалуйста, исправьте ошибки и попробуйте снова.") %>
        <fieldset>
            <label for="Surname">Фамилия:</label>
            <%= Html.TextBox("Surname") %>
            <%= Html.ValidationMessage("Surname","*") %>
            
            <div id="effect" style="visibility: hidden">
                <span id = "surnameValidation"></span>
                <button id="opener">Показать</button>
	        </div>
            
            <label for="Name">Имя:</label>
            <%= Html.TextBox("Name") %>
            <%= Html.ValidationMessage("Name","*") %>
            
            <label for="Patronymic">Отчество:</label>
            <%= Html.TextBox("Patronymic") %>
            <%= Html.ValidationMessage("Patronymic","*") %>
            
            <label for="Sex">Пол:</label>
            <div id="radio">
                <input type="radio" id="sexM" name="Sex" value = "true" checked="checked" /><label for="sexM">Мужской</label>
		        <input type="radio" id="sexW" name="Sex" value = "false"/><label for="sexW">Женский</label>
		    </div>
		
            
            <label for="Birthday">Дата рожения:</label>
            <%= Html.TextBox("Birthday") %>
            <%= Html.ValidationMessage("Birthday","*") %>
            
            <label for="CardName">Номер карты:</label>
            <%= Html.TextBox("CardName") %>
            <%= Html.ValidationMessage("CardName","*") %>
            
            <label for="Note">Комментарий:</label>
            <%= Html.TextArea("Note") %>
            <%= Html.ValidationMessage("Note","*") %>
            <br/><br/>
            <p>
                <input type="submit" value="Создать" />
            </p>
        </fieldset>

    <% } %>

    <div id="left">
        <%= Html.ActionLink("Назад", "Index") %>
    </div>
<script type="text/javascript">
$(document).ready(function(){
    $("#effect:visible" ).removeAttr( "style" ).hide().fadeOut();
    $('#Surname').blur(function() { validate('Surname'); });

    $("#Birthday").mask('99/99/9999');
    $("#radio").buttonset();
});
function validate(property)
{
    $("#effect:visible" ).removeAttr( "style" ).hide().fadeOut();
    $.ajax(
    {
        url: 'Validate',
        data: 'propertyName=' + property + '&propertyValue=' + $('#' + property).val(),
        type: "POST",
        dataType: "json",
        success: function(result)
        {
            if(!result.success)
            {
                var newP = document.createElement('p'),
                    str = '',
                    i,
                    max;

                newP.innerHTML = result.data;
                $("#surnameValidation").html('Внимание! Пациенты с такой фамилией уже существуют.');
                for (i = 0, max = result.data.length; i < max; i++) {
                    str = str + "<br/>" + result.data[i];
                }
 
                $("#dialog").html(str);
                $("#effect" ).removeAttr("style").hide().fadeIn();
            }
        }
    });
}
	
	$.fx.speeds._default = 1000;
	$(function() {
		$( "#dialog" ).dialog({
			autoOpen: false,
			show: "blind",
			hide: "explode",
			height: 412,
			width: 410,
			position: [20,116]
			
		});

		$( "#opener" ).click(function() {
			$( "#dialog" ).dialog( "open" );
			return false;
		});
	});
</script>
<div id="dialog" title="Пациенты">
	<p/>
</div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>

